colors in bash -- script to display all the possible colors.
If you wanted to have colors in the bash output (including the colors in PS1-4), don’t you keep wondering how the color code would look on the terminal. So, I wrote this small script to show the complete color codes. This is how the output would look:
And here is the script:
<td>
<div class="text codecolorer">
#!/bin/bash -<br /> #===============================================================================<br /> #<br /> # FILE: colors.sh<br /> #<br /> # USAGE: ./colors.sh<br /> #<br /> # DESCRIPTION: Bash colors<br /> #<br /> # OPTIONS: ---<br /> # REQUIREMENTS: ---<br /> # BUGS: ---<br /> # NOTES: ---<br /> # AUTHOR: Amit Agarwal (AKA), amit.agarwal@amit-agarwal.co.in<br /> # COMPANY: Individual<br /> # VERSION: 1.0<br /> # CREATED: 09/21/2009 06:12:07 PM IST<br /> # REVISION: ---<br /> #===============================================================================<br /> <br /> for c in `seq 0 255`;<br /> do<br /> t=5;<br /> [[ $c -lt 108 ]]&&t=0;<br /> for i in `seq $t 5`;<br /> do<br /> #Display the codes also for easier lookup in terminal<br /> <!--loginview start-->echo $i;${c}<!--loginview end--><br /> echo -e "<a class="zem_slink" title="Path (computing)" rel="wikipedia" href="http://en.wikipedia.org/wiki/Path_%28computing%29">\\</a>\e[0;48;$i;${c}m|| $i:$c `seq -s+0 $(($COLUMNS/2))|tr -d \'[0-9]\'`\\e[0m";<br /> done;<br /> done<br /> <br /> # setup_colors - Adds colors to array CC for global use<br /> # 30 - Black, 31 - Red, 32 - Green, 33 - Yellow, 34 - Blue,<br /> # 35 - Magenta, 36 - Blue/Green, 37 - White,<br /> # 30/42 - Black on Green \'30\\;42\'<br /> <!--loginview start-->function setup_colors(){<br /> declare -a CC;<br /> for i in `seq 0 7`;<br /> do<br /> ii=$(($i+7));<br /> CC[$i]="\\033[1;3${i}m";<br /> CC[$ii]="\\033[0;3${i}m";<br /> done;<br /> CC[15]="\\033[30;42m";<br /> R=$\'\\033[0;00m\';<br /> X=$\'\\033[1;37m\';<br /> export R X;<br /> }<br /> function display_colors(){<br /> for i in $(seq 0 $((${#CC[@]} - 1))); do echo -e "${CC[$i]}[$i]\\n$R"; done<br /> }
</div>
</td>
</tr>
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
Related articles by Zemanta {."zemanta-related-title"}
- unbound variable – bash completion not working and having issues with other stuff like command not found. (amit-agarwal.co.in)
- Modifying the bashrc or bash startup files. (amit-agarwal.co.in)
- Nature-Inspired Colors for Home Interiors (interiordecorating.suite101.com)
- Dark and Light Blue Colors in Feng Shui (feng-shui-concepts.suite101.com)
- Delete all files in a folder that don\’t match a certain file extension (amit-agarwal.co.in)
Related Articles:
- 2010/05/10 coproc help - a new feature in bash
- 2010/06/03 let a cow tell you your fortune
- 2010/05/27 Checking the links to your site (from affiliates) using cron and bash script.
- 2010/05/17 Script to download all the related videos from youtube with youtube-dl
- 2010/05/20 Startup animation and theme for Fedora 12 onwards.

Authored By Amit Agarwal
Amit Agarwal, Linux and Photography are my hobbies.Creative Commons Attribution 4.0 International License.